
use "$data/DAILY.PANEL.dta", clear

keep if date<=21977

merge m:1 iso2c year month day using "$data/COVID.DAILY.dta"
keep if _merge==1 | _merge==3
drop _merge


merge m:1 iso2c using "$data/first_hth_transmission_NOMISSING.dta"
keep if _merge==1 | _merge==3
drop _merge


replace date_first_hth = 0 if date_first_hth==.

gen postfirsthth = date>=date_first_hth 


merge m:1 iso2c year month day using "$data/GOOGLE.TRENDS.DAILY.dta"
keep if _merge==1 | _merge==3
drop _merge

merge m:1 iso2c year month day using "$data/PLACEBOGOOGLETRENDS.DAILY.dta"
keep if _merge==1 | _merge==3
drop _merge


global placebosearches = " dogs_hits horse_hits insects_hits davinci_hits   nelsonmandela_hits rain_hits rainbow_hits star_hits marsplanet_hits  menstrualcycle_hits "
 

capture label drop google
label define google 1 "recession_hits" 2 "conspiracy_theory_hits" 3 "stockmarket_crash_hits" 4 "prepper_hits"
global googlesearchvar = "recession_hits conspiracy_theory_hits stockmarket_crash_hits prepper_hits"



encode iso2c , gen(iso)
sort iso date


xtset iso date

format date %td


destring $googlesearchvar $placebosearches , replace force

sort iso date


foreach var in covid_confirmed covid_death covid_recovered {

replace `var' = 0 if  `var'==. 

}
 
foreach var in covid_confirmed covid_death covid_recovered {

gen any`var' = `var'>0 if `var'!=. 

}

label variable anycovid_confirmed "First confirmed COVID19 case"
label variable anycovid_death "First confirmed COVID19 death"


gen temp = date if anycovid_confirmed ==1
egen mintemp = min(temp) , by(iso )
egen firstcorona = min(temp) , by(iso )
gen timetofirst = date-firstcorona 
drop temp


replace firstcorona = 51977 if firstcorona ==.

foreach var in $googlesearchvar  $placebosearches {

egen temp = mean(`var') if date<firstcorona, by(iso2c)
egen pre`var' = mean(temp), by(iso2c)
drop temp

}

foreach var in $googlesearchvar $placebosearches  {

replace `var' = `var'/(pre`var'+1)

}




******PLACEBO SEARCHES

keep if year==2020
keep if recession_hits!=.
eststo clear
   
preserve

clear all
eststo clear
estimates drop _all

set obs 10
qui gen x = 1
qui gen y = 1

loc columns = 0

foreach choice in  $placebosearches {

    loc ++columns
    qui eststo col`columns': reg x y

}

restore


/* Statistics */

loc colnum = 1



/* Statistics */

foreach choice in  $placebosearches {

reghdfe  `choice'   anycovid_confirmed      , absorb(iso date) vce(cl iso )
 
    sigstar anycovid_confirmed , prec(3)
    estadd loc thisstat3 = "`r(bstar)'": col`colnum'
    estadd loc thisstat4 = "`r(sestar)'": col`colnum'
	
	estadd loc thisstat6 = string(`e(r2)', "%9.2f"): col`colnum'
	qui sum `choice'  
	estadd loc thisstat7 =  r(N): col`colnum'

    loc ++colnum
}	
	
	loc colnum = 1
foreach choice in  $placebosearches {
	
reghdfe  `choice'   postfirsthth       , absorb(iso date) vce(cl iso )
 
    sigstar postfirsthth , prec(3)
    estadd loc thisstat10 = "`r(bstar)'": col`colnum'
    estadd loc thisstat11 = "`r(sestar)'": col`colnum'

	estadd loc thisstat13 = string(`e(r2)', "%9.2f"): col`colnum'
	qui sum `choice'  
	estadd loc thisstat14 =  r(N): col`colnum'

	      loc ++colnum
}	


loc l = 1
foreach choice in  $placebosearches {

reghdfe `choice'   anycovid_confirmed      , absorb(iso date) vce(cl iso )
estadd loc thisstat15 = "`e(N_clust)'" : col`l'
loc ++l
}
	
forval l = 1/10 {
estadd loc thisstat16 = "X": col`l'
estadd loc thisstat17 = "X": col`l'
}	

loc rowlabels " "{\bf Panel  A: First confirmed case}" " " "First confirmed case" " " " " "\midrule R$^2$" "Number of Observations " "\midrule {\bf Panel  B: First human-to-human  transmission}" " "  "First human-to-human  transmission" " "" "  "\midrule R$^2$" "Number of Observations" "\midrule  Number of countries" "Country FE" "Day FE""




loc rowstats ""




forval i = 1/17 {
    loc rowstats "`rowstats' thisstat`i'"
}



esttab  using "$output/tables/Placebo_DD_results.tex", replace cells(none) booktabs nonotes  compress alignment(c) nogap noobs nobaselevels label stats(`rowstats', labels(`rowlabels')) ///
mtitle("Dog" "Horse" "Insect" "DaVinci"  "Nelson Mandela" "Rain" "Rainbow" "Stars" "Mars (planet)"  "Menstrual Cycle") ///
mgroups("Impact on google searches for",  pattern(1 0 0 0 0   ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))





